package service

import (
	"MessageSendService/app/api/internal/process"
	"MessageSendService/app/api/internal/process/action"
	"MessageSendService/app/common/log"
	"MessageSendService/app/common/models/vo"
	"go.uber.org/zap"
)

type SendMessageService struct {
}

func NewSendMessageService() *SendMessageService {
	return &SendMessageService{}
}

// SendMessage todo 这里还要处理批量发送的逻辑
func (s *SendMessageService) SendMessage(request vo.BatchMessageRequest) error {
	log.GetLogger().Info("service发送信息", zap.Any("request", request))

	//构造责任链的参数
	sendModelContext := &process.ProcessContext{Code: 1,
		ProcessModel: process.ProcessModel{MessageTemplateId: request.MessageTemplateId, MessageParam: request.MessageParamList},
		NeedBreak:    false}
	//这里需要调用责任链发送各种类型的消息
	processController := process.NewProcessController()
	//前置处理
	processController.AddProcess(1, action.NewPreParamAction())
	//拼接参数
	processController.AddProcess(1, action.NewAssambleAction(messageTemplateService{}))
	//后置处理
	processController.AddProcess(1, action.NewPostParamAction())
	//发送消息到Kafka
	processController.AddProcess(1, action.NewSendMQAction()) //真正发送消息的action

	err := processController.ProcessExecute(sendModelContext)
	if err != nil {
		return err
	}
	return nil
}
